<!DOCTYPE html>
            
<HTML>
<HEAD>
<meta name="booktitle" content="Developing Applications With Objective Caml" >
 <meta charset="ISO-8859-1"><meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
<META name="GENERATOR" content="hevea 1.05-7 of 2000-02-24">
<META NAME="Author" CONTENT="Christian.Queinnec@lip6.fr">
<LINK rel=stylesheet type="text/css" href="videoc-ocda.css">
<script language="JavaScript" src="videoc.js"><!--
//--></script>
<TITLE>
 Compilation
</TITLE>
</HEAD>
<BODY class="regularBody">
<A HREF="book-ora065.html"><IMG SRC ="previous_motif.gif" ALT="Previous"></A>
<A HREF="index.html"><IMG SRC ="contents_motif.gif" ALT="Contents"></A>
<A HREF="book-ora067.html"><IMG SRC ="next_motif.gif" ALT="Next"></A>
<HR>

<H2> Compilation</H2>The distribution of a language depends on the processor and the operating
system. For each
architecture, a distribution of
Objective CAML
contains the toplevel system, the bytecode compiler, and in most cases a native compiler.<BR>
<BR>
<A NAME="toc92"></A>
<H3> Command Names</H3>
<A NAME="@concepts125"></A>
<A NAME="@fonctions188"></A>
<A NAME="@fonctions189"></A>
<A NAME="@fonctions190"></A>
<A NAME="@fonctions191"></A>
<A NAME="@fonctions192"></A>
<A NAME="@fonctions193"></A>
<A NAME="@fonctions194"></A>
The figure <A HREF="book-ora066.html#fig-commandes">7.5</A> shows the command names of the different compilers in the various Objective CAML distributions. The first four commands are available for all distributions.<BR>
<BR>
<BLOCKQUOTE><DIV ALIGN=center><HR WIDTH="80%" SIZE=2></DIV>
<DIV ALIGN=center>
<TABLE BORDER=1 CELLSPACING=0 CELLPADDING=1>
<TR><TD  ALIGN=left NOWRAP><TT>ocaml</TT></TD>
<TD  ALIGN=left NOWRAP>toplevel loop</TD>
</TR>
<TR><TD  ALIGN=left NOWRAP><TT>ocamlrun</TT></TD>
<TD  ALIGN=left NOWRAP>bytecode interpreter</TD>
</TR>
<TR><TD  ALIGN=left NOWRAP><TT>ocamlc</TT></TD>
<TD  ALIGN=left NOWRAP>bytecode batch compiler</TD>
</TR>
<TR><TD  ALIGN=left NOWRAP><TT>ocamlopt</TT></TD>
<TD  ALIGN=left NOWRAP>native code batch compiler</TD>
</TR>
<TR><TD  ALIGN=left NOWRAP><TT>ocamlc.opt</TT></TD>
<TD  ALIGN=left NOWRAP>optimized bytecode batch compiler</TD>
</TR>
<TR><TD  ALIGN=left NOWRAP><TT>ocamlopt.opt</TT></TD>
<TD  ALIGN=left NOWRAP>optimized native code batch compiler</TD>
</TR>
<TR><TD  ALIGN=left NOWRAP><TT>ocamlmktop</TT></TD>
<TD  ALIGN=left NOWRAP>new toplevel constructor</TD>
</TR></TABLE>
<BR>
<DIV ALIGN=center>Figure 7.5: Commands for compiling.</DIV><BR>

<A NAME="fig-commandes"></A>
</DIV>
<DIV ALIGN=center><HR WIDTH="80%" SIZE=2></DIV></BLOCKQUOTE>The optimized compilers are themselves compiled with the Objective CAML native compiler. They compile faster but are otherwise identical to their unoptimized counterparts.<BR>
<BR>
<A NAME="toc93"></A>
<H3> Compilation Unit</H3>
<A NAME="@concepts126"></A>
<A NAME="@concepts127"></A>A compilation unit corresponds to the smallest piece of an
Objective CAML program
that can be compiled. For the interactive system, the unit of compilation
corresponds to a phrase of the language. For the batch compiler, the unit of compilation is two files: the source
file, and the interface file. The interface file is optional -
if it does not exist, then all global declarations in the source file will be visible to other compilation units. The construction of interface files is described in the chapter on module programming (<A HREF="index.html#chap-modules">14</A>). The two file types (source and interface) are differentiated by separate file extensions.<BR>
<BR>
<A NAME="toc94"></A>
<H3> Naming Rules for File Extensions</H3>
<A NAME="@concepts128"></A>
<A NAME="@concepts129"></A>
<A NAME="@concepts130"></A>
Figure <A HREF="book-ora066.html#fig-fichiers">7.6</A> presents the extensions of different files used for Objective CAML and C programs.<BR>
<BR>
<BLOCKQUOTE><DIV ALIGN=center><HR WIDTH="80%" SIZE=2></DIV>
<DIV ALIGN=center>
<TABLE BORDER=1 CELLSPACING=0 CELLPADDING=1>
<TR><TD  ALIGN=left NOWRAP>extension</TD>
<TD  ALIGN=left NOWRAP>meaning</TD>
</TR>
<TR><TD  ALIGN=left NOWRAP><TT>.ml</TT></TD>
<TD  ALIGN=left NOWRAP>source file</TD>
</TR>
<TR><TD  ALIGN=left NOWRAP><TT>.mli</TT></TD>
<TD  ALIGN=left NOWRAP>interface file</TD>
</TR>
<TR><TD  ALIGN=left NOWRAP><TT>.cmo</TT></TD>
<TD  ALIGN=left NOWRAP>object file (bytecode)</TD>
</TR>
<TR><TD  ALIGN=left NOWRAP><TT>.cma</TT></TD>
<TD  ALIGN=left NOWRAP>library object file (bytecode)</TD>
</TR>
<TR><TD  ALIGN=left NOWRAP><TT>.cmi</TT></TD>
<TD  ALIGN=left NOWRAP>compiled interface file</TD>
</TR>
<TR><TD  ALIGN=left NOWRAP><TT>.cmx</TT></TD>
<TD  ALIGN=left NOWRAP>object file (native)</TD>
</TR>
<TR><TD  ALIGN=left NOWRAP><TT>.cmxa</TT></TD>
<TD  ALIGN=left NOWRAP>library object file (native)</TD>
</TR>
<TR><TD  ALIGN=left NOWRAP><TT>.c</TT></TD>
<TD  ALIGN=left NOWRAP>C source file</TD>
</TR>
<TR><TD  ALIGN=left NOWRAP><TT>.o</TT></TD>
<TD  ALIGN=left NOWRAP>C object file (native)</TD>
</TR>
<TR><TD  ALIGN=left NOWRAP><TT>.a</TT></TD>
<TD  ALIGN=left NOWRAP>C library object file (native)</TD>
</TR></TABLE>
<BR>
<DIV ALIGN=center>Figure 7.6: File extensions.</DIV><BR>

<A NAME="fig-fichiers"></A>
</DIV>
<DIV ALIGN=center><HR WIDTH="80%" SIZE=2></DIV></BLOCKQUOTE>The files <TT>example.ml</TT> and <TT>example.mli</TT> form a compilation unit. The compiled interface file (<TT>example.cmi</TT>) is used for both the bytecode and native code compiler. 
The C language related files are used when integrating C code with Objective CAML code.
(<A HREF="index.html#chap-interop">12</A>).<BR>
<BR>
<A NAME="toc95"></A>
<H3> The Bytecode Compiler</H3>
<A NAME="@concepts131"></A>
<A NAME="@concepts132"></A>
<A NAME="@concepts133"></A>
<A NAME="@fonctions195"></A>The general form of the batch compiler commands are:<BR>
<BR>
<TT>command </TT><TT><EM>options</EM></TT><TT> </TT><TT><EM>file_name</EM></TT><BR>
<BR>
For example:
<PRE>
ocamlc -c example.ml
</PRE>The command-line options for both the native and bytecode compilers follow typical Unix conventions. Each option is
prefixed by the character <CODE>-</CODE>. File extensions are interpreted in the manner described by figure <A HREF="book-ora066.html#fig-fichiers">7.6</A>. In the above example, the file <TT>example.ml</TT> is considered an Objective CAML source file and is compiled. The compiler will produce the files <TT>example.cmo</TT> and <TT>example.cmi</TT>. The option <CODE>-c</CODE> informs the compiler to generate individual object
files, which may be linked at a later time.
 Without this option, the compiler will produce an executable file named <CODE>a.out</CODE>.<BR>
<BR>
The table in figure <A HREF="book-ora066.html#fig-optbytep">7.7</A> describes the principal options of the bytecode compiler. The table in figure <A HREF="book-ora066.html#fig-optbytea">7.8</A> indicates other possible options.
<BLOCKQUOTE><DIV ALIGN=center><HR WIDTH="80%" SIZE=2></DIV>
<DIV ALIGN=center>
<TABLE BORDER=1 CELLSPACING=0 CELLPADDING=1>
<TR><TD  ALIGN=center NOWRAP COLSPAN=2>Principal options</TD>
</TR>
<TR><TD  VALIGN=top ALIGN=left NOWRAP><TT>-a</TT></TD>
<TD  VALIGN=top ALIGN=left>construct a runtime library</TD>
</TR>
<TR><TD  VALIGN=top ALIGN=left NOWRAP><TT>-c</TT></TD>
<TD  VALIGN=top ALIGN=left>compile without linking</TD>
</TR>
<TR><TD  VALIGN=top ALIGN=left NOWRAP><TT>-o</TT> <I>name_of_executable</I></TD>
<TD  VALIGN=top ALIGN=left>specify the name of the executable</TD>
</TR>
<TR><TD  VALIGN=top ALIGN=left NOWRAP><TT>-linkall</TT></TD>
<TD  VALIGN=top ALIGN=left>link with all libraries used</TD>
</TR>
<TR><TD  VALIGN=top ALIGN=left NOWRAP><TT>-i</TT></TD>
<TD  VALIGN=top ALIGN=left>display all compiled global declarations</TD>
</TR>
<TR><TD  VALIGN=top ALIGN=left NOWRAP><TT>-pp</TT> <I>command</I></TD>
<TD  VALIGN=top ALIGN=left>uses <I>command</I> as preprocessor</TD>
</TR>
<TR><TD  VALIGN=top ALIGN=left NOWRAP><TT>-unsafe</TT></TD>
<TD  VALIGN=top ALIGN=left>turn off index checking</TD>
</TR>
<TR><TD  VALIGN=top ALIGN=left NOWRAP><TT>-v</TT></TD>
<TD  VALIGN=top ALIGN=left>display the version of the compiler</TD>
</TR>
<TR><TD  VALIGN=top ALIGN=left NOWRAP><TT>-w</TT> <I>list</I></TD>
<TD  VALIGN=top ALIGN=left>choose among the <I>list</I> the level of warning message 
 (see fig. <A HREF="book-ora066.html#fig-warning">7.9</A>)</TD>
</TR>
<TR><TD  VALIGN=top ALIGN=left NOWRAP><TT>-impl</TT> <I>file</I></TD>
<TD  VALIGN=top ALIGN=left>indicate that <I>file</I> is a Caml source (.ml)</TD>
</TR>
<TR><TD  VALIGN=top ALIGN=left NOWRAP><TT>-intf</TT> <I>file</I></TD>
<TD  VALIGN=top ALIGN=left>indicate that <I>file</I> is a Caml interface (.mli)</TD>
</TR>
<TR><TD  VALIGN=top ALIGN=left NOWRAP><TT>-I</TT> <I>directory</I></TD>
<TD  VALIGN=top ALIGN=left>add <I>directory</I> in the list of directories</TD>
</TR></TABLE>
<BR>
<DIV ALIGN=center>Figure 7.7: Principal options of the bytecode compiler.</DIV><BR>

<A NAME="fig-optbytep"></A>
</DIV>
<DIV ALIGN=center><HR WIDTH="80%" SIZE=2></DIV></BLOCKQUOTE>
<BLOCKQUOTE><DIV ALIGN=center><HR WIDTH="80%" SIZE=2></DIV>
<DIV ALIGN=center>
<TABLE BORDER=1 CELLSPACING=0 CELLPADDING=1>
<TR><TD  ALIGN=center NOWRAP COLSPAN=2>Other options</TD>
</TR>
<TR><TD  ALIGN=left NOWRAP>light process</TD>
<TD  ALIGN=left NOWRAP><TT>-thread</TT> (<A HREF="index.html#chap-PC">19</A>, page <A HREF="index.html#chap-PC">??</A>)</TD>
</TR>
<TR><TD  ALIGN=left NOWRAP>linking</TD>
<TD  ALIGN=left NOWRAP><TT>-g</TT>, <TT>-noassert</TT> 
 (<A HREF="index.html#chap-Aprog">10</A>, page <A HREF="index.html#chap-Aprog">??</A>)</TD>
</TR>
<TR><TD  ALIGN=left NOWRAP>standalone executable</TD>
<TD  ALIGN=left NOWRAP><TT>-custom</TT>, <TT>-cclib</TT>, <TT>-ccopt</TT>, <TT>-cc</TT> 
 (see page <A HREF="book-ora067.html#sec-standalone">??</A>)</TD>
</TR>
<TR><TD  ALIGN=left NOWRAP><I>runtime</I></TD>
<TD  ALIGN=left NOWRAP><TT>-make-runtime </TT>, <TT>-use-runtime </TT></TD>
</TR>
<TR><TD  ALIGN=left NOWRAP>C interface</TD>
<TD  ALIGN=left NOWRAP><TT>-output-obj</TT> 
 (<A HREF="index.html#chap-IC">12</A>, page <A HREF="index.html#chap-IC">??</A>)</TD>
</TR></TABLE>
<BR>
<DIV ALIGN=center>Figure 7.8: Other options for the bytecode compiler.</DIV><BR>

<A NAME="fig-optbytea"></A>
</DIV>
<DIV ALIGN=center><HR WIDTH="80%" SIZE=2></DIV></BLOCKQUOTE>To display the list of bytecode compiler options, use the option <TT>-help</TT>.<BR>
<BR>
The different levels of warning message are described in figure <A HREF="book-ora066.html#fig-warning">7.9</A>. A message level is a switch (enable/disable) represented by a letter. An upper case letter activates the level and a lower case letter disables it.
<BLOCKQUOTE><DIV ALIGN=center><HR WIDTH="80%" SIZE=2></DIV>
<DIV ALIGN=center>
<TABLE BORDER=1 CELLSPACING=0 CELLPADDING=1>
<TR><TD  ALIGN=left NOWRAP>Principal levels</TD>
<TD  ALIGN=left NOWRAP>&nbsp;</TD>
</TR>
<TR><TD  ALIGN=left NOWRAP><TT>A/a</TT></TD>
<TD  ALIGN=left NOWRAP>enable/disable all messages</TD>
</TR>
<TR><TD  ALIGN=left NOWRAP><TT>F/f</TT></TD>
<TD  ALIGN=left NOWRAP>partial application in a sequence</TD>
</TR>
<TR><TD  ALIGN=left NOWRAP><TT>P/p</TT></TD>
<TD  ALIGN=left NOWRAP>for incomplete pattern matching</TD>
</TR>
<TR><TD  ALIGN=left NOWRAP><TT>U/u</TT></TD>
<TD  ALIGN=left NOWRAP>for missing cases in pattern matching</TD>
</TR>
<TR><TD  ALIGN=left NOWRAP><TT>X/x</TT></TD>
<TD  ALIGN=left NOWRAP>enable/disable all other messages</TD>
</TR>
<TR><TD  ALIGN=left NOWRAP>for hidden object</TD>
<TD  ALIGN=left NOWRAP><TT>M/m</TT> and <TT>V/v</TT> (see chapter <A HREF="index.html#chap-POO">15</A>)</TD>
</TR></TABLE>
<BR>
<DIV ALIGN=center>Figure 7.9: Description of compilation warnings.</DIV><BR>

<A NAME="fig-warning"></A>
</DIV>
<DIV ALIGN=center><HR WIDTH="80%" SIZE=2></DIV></BLOCKQUOTE>By default, the highest level (<TT>A</TT>) is chosen by the compiler.<BR>
<BR>
Example usage of the bytecode compiler is given in figure <A HREF="book-ora066.html#fig-sessionbyte">7.10</A>.
<BLOCKQUOTE><DIV ALIGN=center><HR WIDTH="80%" SIZE=2></DIV>
<DIV ALIGN=center>
<IMG SRC="book-ora028.gif">
<BR>
<BR>
<DIV ALIGN=center>Figure 7.10: Session with the bytecode compiler.</DIV><BR>

<A NAME="fig-sessionbyte"></A>
</DIV>
<DIV ALIGN=center><HR WIDTH="80%" SIZE=2></DIV></BLOCKQUOTE><A NAME="toc96"></A>
<H3> Native Compiler</H3>
<A NAME="@concepts134"></A>
<A NAME="@fonctions196"></A>
The native compiler has behavior similar to the bytecode compiler, but
produces different types of files. The compilation options are generally the same as those described in figures <A HREF="book-ora066.html#fig-optbytep">7.7</A> and <A HREF="book-ora066.html#fig-optbytea">7.8</A>. It is necessary to take out the options related to <I>runtime</I> in figure <A HREF="book-ora066.html#fig-optbytea">7.8</A>. Options specific to the native compiler are given in figure <A HREF="book-ora066.html#fig-optnatif">7.11</A>. The
different <I>warning</I> levels are same.
<BLOCKQUOTE><DIV ALIGN=center><HR WIDTH="80%" SIZE=2></DIV>
<DIV ALIGN=center>
<TABLE BORDER=1 CELLSPACING=0 CELLPADDING=1>
<TR><TD  ALIGN=left NOWRAP><TT>-compact</TT></TD>
<TD  ALIGN=left NOWRAP>optimize the produced code for space</TD>
</TR>
<TR><TD  ALIGN=left NOWRAP><TT>-S</TT></TD>
<TD  ALIGN=left NOWRAP>keeps the assembly code in a file</TD>
</TR>
<TR><TD  ALIGN=left NOWRAP><TT>-inline</TT> <EM>level</EM></TD>
<TD  ALIGN=left NOWRAP>set the aggressiveness of inlining</TD>
</TR></TABLE>
<BR>
<DIV ALIGN=center>Figure 7.11: Options specific to the native compiler.</DIV><BR>

<A NAME="fig-optnatif"></A>
</DIV>
<DIV ALIGN=center><HR WIDTH="80%" SIZE=2></DIV></BLOCKQUOTE><A NAME="@concepts135"></A>Inlining is an elaborated version of macro-expansion in the preprocessing stage. 
For functions whose arguments are fixed, inlining replaces each function call with the body of the function called. Several different calls produce several copies of the function body. Inlining avoids the overhead that comes with function call setup and
return, at the expense of object code size. Principal inlining levels are:<BR>
<BR>
<UL>
<LI>
 0&nbsp;: The expansion will be done only when it will not increase the size of the object code.

<LI> 1&nbsp;: This is the default value; it accepts a light increase on code size.

<LI> <I>n</I>&gt;1&nbsp;: Raise the tolerance for growth in the code. Higher values result in more inlining.
</UL><A NAME="toc97"></A>
<H3> Toplevel Loop</H3>
<A NAME="refsec-toplevel"></A>
<A NAME="@fonctions197"></A>
<A NAME="@concepts136"></A>
<A NAME="@concepts137"></A>
<A NAME="@concepts138"></A>
The toplevel loop provides only two command line options.
<UL>
<LI>
 <TT>-I</TT> <I>directory</I>: adds the indicated directory to the list of
search paths for compiled source files.

<LI> <TT>-unsafe</TT>: instructs the compiler not to do bounds checking on
array and string accesses.
</UL><A NAME="@concepts139"></A>
The toplevel loop provides several directives which
can be used to interactively modify its behavior. They are described in figure <A HREF="book-ora066.html#fig-directives">7.12</A>. All these directives begin with the character <CODE>#</CODE> and
are terminated by <CODE>;;</CODE>.
<BLOCKQUOTE><DIV ALIGN=center><HR WIDTH="80%" SIZE=2></DIV>
<DIV ALIGN=center>
<TABLE BORDER=1 CELLSPACING=0 CELLPADDING=1>
<TR><TD  ALIGN=left NOWRAP><TT>#</TT><TT>quit</TT> <CODE>;;</CODE></TD>
<TD  ALIGN=left NOWRAP>quit from the toplevel interaction</TD>
</TR>
<TR><TD  ALIGN=left NOWRAP><TT>#</TT><TT>directory</TT> <EM>directory</EM> <CODE>;;</CODE></TD>
<TD  ALIGN=left NOWRAP>add the directory to the search path</TD>
</TR>
<TR><TD  ALIGN=left NOWRAP><TT>#</TT><TT>cd</TT> <EM>directory</EM> <CODE>;;</CODE></TD>
<TD  ALIGN=left NOWRAP>change the working directory</TD>
</TR>
<TR><TD  ALIGN=left NOWRAP><TT>#</TT><TT>load</TT> <EM>object_file</EM> <CODE>;;</CODE></TD>
<TD  ALIGN=left NOWRAP>load an object file (<TT>.cmo</TT>)</TD>
</TR>
<TR><TD  ALIGN=left NOWRAP><TT>#</TT><TT>use</TT> <EM>source_file</EM> <CODE>;;</CODE></TD>
<TD  ALIGN=left NOWRAP>compile and load a source file</TD>
</TR>
<TR><TD  ALIGN=left NOWRAP><TT>#</TT><TT>print_depth</TT> <EM>depth</EM> <CODE>;;</CODE></TD>
<TD  ALIGN=left NOWRAP>modify the depth of printing</TD>
</TR>
<TR><TD  ALIGN=left NOWRAP><TT>#</TT><TT>print_length</TT> <EM>width</EM> <CODE>;;</CODE></TD>
<TD  ALIGN=left NOWRAP>modify the length of printing</TD>
</TR>
<TR><TD  ALIGN=left NOWRAP><TT>#</TT><TT>install_printer</TT> <EM>function</EM> <CODE>;;</CODE></TD>
<TD  ALIGN=left NOWRAP>specify a printing function</TD>
</TR>
<TR><TD  ALIGN=left NOWRAP><TT>#</TT><TT>remove_printer</TT> <EM>function</EM> <CODE>;;</CODE></TD>
<TD  ALIGN=left NOWRAP>remove a printing function</TD>
</TR>
<TR><TD  ALIGN=left NOWRAP><TT>#</TT><TT>trace</TT> <EM>function</EM> <CODE>;;</CODE></TD>
<TD  ALIGN=left NOWRAP>trace the arguments of the function</TD>
</TR>
<TR><TD  ALIGN=left NOWRAP><TT>#</TT><TT>untrace</TT> <EM>function</EM> <CODE>;;</CODE></TD>
<TD  ALIGN=left NOWRAP>stop tracing the function</TD>
</TR>
<TR><TD  ALIGN=left NOWRAP><TT>#</TT><TT>untrace_all</TT> <CODE>;;</CODE></TD>
<TD  ALIGN=left NOWRAP>stop all tracing</TD>
</TR></TABLE>
<BR>
<DIV ALIGN=center>Figure 7.12: Toplevel loop directives.</DIV><BR>

<A NAME="fig-directives"></A>
</DIV>
<DIV ALIGN=center><HR WIDTH="80%" SIZE=2></DIV></BLOCKQUOTE>The directives dealing with directories respect the conventions of the operating
system used.<BR>
<BR>
The loading directives do not have exactly the same behavior. The directive
<TT>#use</TT> reads the source file as if it was typed directly in the toplevel loop. The
directive <CODE>#load</CODE> loads the file with the extension <CODE>.cmo</CODE>. In the later case, the global declarations of this file are not directly accessible.
 If the file <TT>example.ml</TT> contains the global declaration <TT>f</TT>, then once the bytecode is loaded (<CODE>#load "example.cmo";;</CODE>), it is assumed that the value of <TT>f</TT> could be accessed by
<TT>Example.f</TT>, where the first letter of the file is capitalized. This notation comes from the module system of Objective CAML (see chapter <A HREF="index.html#chap-PM">14</A>, page <A HREF="index.html#chap-PM">??</A>).<BR>
<BR>
The directives for the depth and width of printing are used to control the display
of values. This is useful when it is necessary to display the contents of a value in detail. <BR>
<BR>
The directives for printer redefinition are used to install or remove a user defined printing function for values of a specified type. In order to integrate these printer functions into the default printing procedure, it is necessary to use the <TT>Format</TT>
library(<A HREF="index.html#chap-Bibliotheques">8</A>) for the definition.<BR>
<BR>
The directives for tracing arguments and results of functions are particularly useful for debugging programs. They will be discussed in the chapter on program analysis (<A HREF="index.html#chap-Aprog">10</A>).<BR>
<BR>
Figure <A HREF="book-ora066.html#fig-topsession">7.13</A> shows a session in the toplevel loop.
<A NAME="@concepts140"></A>
<BLOCKQUOTE><DIV ALIGN=center><HR WIDTH="80%" SIZE=2></DIV>
<DIV ALIGN=center>
<IMG SRC="book-ora029.gif">
<BR>
<BR>
<DIV ALIGN=center>Figure 7.13: Session with the toplevel loop.</DIV><BR>

<A NAME="fig-topsession"></A>
</DIV>
<DIV ALIGN=center><HR WIDTH="80%" SIZE=2></DIV></BLOCKQUOTE><A NAME="toc98"></A>
<H3> Construction of a New Interactive System</H3>
<A NAME="sec-new-toplevel"></A>
<A NAME="@concepts141"></A>
<A NAME="@fonctions198"></A>
The command <TT>ocamlmktop</TT> can be used to construct a new toplevel
executable which has specific library modules loaded by default. For example, <TT>ocamlmktop</TT> is often used for pulling native object code libraries (typically written in C) into a new toplevel.<BR>
<BR>
<TT>ocamlmktop</TT> options are a subset of those used by the bytecode compiler (<TT>ocamlc</TT>):
<DIV ALIGN=center>
<TABLE CELLSPACING=2 CELLPADDING=0>
<TR><TD  ALIGN=center NOWRAP><TT>-cclib</TT> <EM>libname</EM>, <TT>-ccopt</TT> <EM>option</EM>, <TT>-custom</TT>,
<TT>-I</TT> <EM>directory</EM> <TT>-o</TT> <EM>executable_name</EM></TD>
</TR></TABLE>
</DIV>
The chapter on graphics programming (<A HREF="index.html#chap-PG">5</A>, page <A HREF="index.html#chap-PG">??</A>) uses this command for constructing a toplevel system containing the <TT>Graphics</TT>
library in the following manner:
<PRE>
ocamlmktop -custom -o mytoplevel graphics.cma -cclib \ 
           -I/usr/X11/lib -cclib -lX11
</PRE>This command constructs an executable with the name <TT>mytoplevel</TT>, containing
the bytecode library <TT>graphics.cma</TT>. This standalone executable (<TT>-custom</TT>, see the following section) will be linked to the library <TT>X11</TT> (<TT>libX11.a</TT>) which in turn will be looked up in the path <TT>/usr/X11/lib</TT>.<BR>
<BR>
<HR>
<A HREF="book-ora065.html"><IMG SRC ="previous_motif.gif" ALT="Previous"></A>
<A HREF="index.html"><IMG SRC ="contents_motif.gif" ALT="Contents"></A>
<A HREF="book-ora067.html"><IMG SRC ="next_motif.gif" ALT="Next"></A>
</BODY>
</HTML>
